﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using System.Data;

namespace Core.Dao
{
    class UserTypeDao
    {
        public bool insert(UserType userType)
        {
            object[,] param = {
                {"@Name", userType.Name},
                {"@Desc", userType.Desc},
            };
            String sql = "insert into USER_TYPES(UST_NAME, UST_DESC) " +
                "values(@Name, @Desc)";
            return DB.exec(sql, param);
        }

        public bool update(UserType userType)
        {
            object[,] param = {
                {"@Name", userType.Name},
                {"@Desc", userType.Desc},
                {"@id", userType.Id},
            };
            String sql = "update USER_TYPES set UST_NAME = @Name, UST_DESC = @Desc " +
                "where UST_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "delete from USER_TYPES where UST_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(String ids)
        {
            object[,] param = {
                {"@ids", ids}   
            };
            String sql = "delete from USER_TYPES where UST_ID in (" + ids + ")";
            return DB.exec(sql);
        }

        public DataTable get(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "select * from USER_TYPES where UST_ID = @id";
            return DB.getData(sql, param);
        }

        public DataTable getAll()
        {
            String sql = "select * from USER_TYPES order by UST_NAME";
            return DB.getData(sql);
        }
    }
}
